package com.itheima.controller;

import com.itheima.bean.User;
import com.itheima.service.StudentService;
import com.itheima.service.UserService;
import com.itheima.service.impl.UserServiceImpl;
import org.apache.commons.beanutils.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;


@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService userService;

    /**
     * 处理登录的请求
     */
    //@RequestMapping("/login")
    @PostMapping("/login")
    protected boolean login(@RequestBody User user, HttpSession session){

        User existUser=userService.login(user);

        //3 判断如果user!=null,说明登录成功，将user保存到session
        if(existUser!=null){
            //登录成功
            session.setAttribute("user",existUser);
        }
        return existUser!=null;//true表示登录成功,false表示登录失败
    }

}
